package com.haoshuang.zhouzhoubang.ui.page.home.settings

import com.haoshuang.zhouzhoubang.base.BaseCommonViewModel
import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.TeamSettingsInfoBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class StoreSettingsViewModel : BaseCommonViewModel() {

    /**
     * 设置订单奖励分配
     */
    val setOrderAwardData = StatefulMutableLiveData<Any>()
    fun setOrderAward(
        team_id: String?,
        order_award: Int
    ) = netRequest {
        start { setOrderAwardData.value = StateData.Loading }
        request { ApiRepo.setOrderAward(team_id, order_award) }
        success { setOrderAwardData.value = StateData.Success(it) }
        error { code, msg ->
            setOrderAwardData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 获取门店设置信息
     */
    val getTeamSettingsInfoData = StatefulMutableLiveData<ResponseBean<TeamSettingsInfoBean>>()
    fun getTeamSettingsInfo() = netRequest {
        start { getTeamSettingsInfoData.value = StateData.Loading }
        request { ApiRepo.getTeamSettingsInfo() }
        success { getTeamSettingsInfoData.value = StateData.Success(it) }
        error { code, msg ->
            getTeamSettingsInfoData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 设置门店违约扣除
     */
    val setOrderDeditData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun setOrderDedit(order_dedit: Int) = netRequest {
        start { setOrderDeditData.value = StateData.Loading }
        request { ApiRepo.setOrderDedit(order_dedit)  }
        success { setOrderDeditData.value = StateData.Success(it) }
        error { code, msg ->
            setOrderDeditData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 更新门店服务区域
     */
    val updateTeamAreaData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun updateTeamArea(city_id: String) = netRequest {
        start { updateTeamAreaData.value = StateData.Loading }
        request { ApiRepo.updateTeamArea(city_id)  }
        success { updateTeamAreaData.value = StateData.Success(it) }
        error { code, msg ->
            updateTeamAreaData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 设置门店优先接单距离
     */
    val setOrderDistanceData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun setOrderDistance(order_distance: String) = netRequest {
        start { setOrderDistanceData.value = StateData.Loading }
        request { ApiRepo.setOrderDistance(order_distance)  }
        success { setOrderDistanceData.value = StateData.Success(it) }
        error { code, msg ->
            setOrderDistanceData.value = StateData.Error(code, msg)
        }
    }

}